package controller;

import dto.Result;
import service.TableService;
import util.JsonUtils;
import util.StringUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/table/findByPage")
public class TableFindByPageController extends HttpServlet {
    private TableService ts = new TableService();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //默认起始页
        int pageNow = 1;
        //默认数据条
        int pageSize = 4;
        //接收前端传递的值
        String page = req.getParameter("page");
        String limit = req.getParameter("limit");
        if (StringUtils.isNotNull(page) && StringUtils.isNotNull(limit)) {
            pageNow = Integer.parseInt(page);
            pageSize = Integer.parseInt(limit);
        }

        //执行分页查询
        Result rs = ts.findByPage(pageNow, pageSize);
        //将数据发送到前台
        JsonUtils.jsonWrite(resp,rs);
    }
}
